<!DOCTYPE HTML>
<html>
<head>
<!-- Force latest IE rendering engine or ChromeFrame if installed -->
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
<meta charset="utf-8">
<title>jQuery File Upload Demo - Basic Plus version</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap styles -->
<link rel="stylesheet" href="__PUBLIC__/jquery_upload/css/bootstrap.min.css">
<!-- Generic page styles -->
<link rel="stylesheet" href="css/style.css">
<!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
<link rel="stylesheet" href="__PUBLIC__/jquery_upload/css/jquery.fileupload.css">
<style>
	video{
		width: 430px;
		height: 250px;
	}
</style>
</head>
<body>

<div class="container" style="padding: 20px 20px 70px;">
        <ul class="nav nav-tabs">
			<li><a href="{:U('AppGroup/index')}">群列表</a></li>
			<li><a href="{:U('AppGroup/add')}">新增群</a></li>
			<li class="active"><a href="{:U('AppGroup/upload_pic')}">设置群背景音乐</a></li>
		</ul>
    <br>
    <br>
    <!-- The fileinput-button span is used to style the file input field as button -->
    <span class="btn btn-success fileinput-button">
        <i class="glyphicon glyphicon-plus"></i>
        <span>上传mp3</span>
        <!-- The file input field used as target for the file upload widget -->
        <input id="fileupload" type="file" name="files[]" multiple>
    </span>
    <br>
    <br>
    <!-- The global progress bar -->
    <div id="progress" class="progress">
        <div class="progress-bar progress-bar-success"></div>
    </div>
    <!-- The container for the uploaded files -->
    <div id="files" class="files"></div>
    <br>
    <form id="myform1" method="post"  action="{:U('AppGroup/upload_pic')}">
    	<!--<input type="hidden" name="video[]"/>-->
    	<span class="btn btn-success fileinput-button">
        <i class="glyphicon glyphicon-plus"></i>
        <span>提交</span>
        <!-- The file input field used as target for the file upload widget -->
        <input type="submit">
    </span>
    </form>
    <br/>
    
    <table class="table table-hover">
   <caption><h3>群 mp3 列表</h3></caption>
   <thead>
      <tr>
         <th>歌曲名称</th>
         <th width="50%">歌曲访问路径</th>
         <th>上传时间</th>
         <th>操作</th>
      </tr>
   </thead>
   <tbody>
   	<foreach name="list" item="vo">
   		<tr>
         <td>{$vo.name}</td>
         <td>{$vo.url}</td>
         <td>{$vo.creat_time}</td>
         <td><a href="delete_pic/id/{$vo.id}">删除</a></td>
      </tr>
   	</foreach>
      
   </tbody>
</table>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">说明</h3>
        </div>
        <div class="panel-body">
            <ul>
                <li>每首音频的大小不能超过 <strong>15 MB</strong></li>
                <li>视频格式只能是 (<strong>mp3)</li>
                <li>允许拖动上传</li>
            </ul>
        </div>
    </div>
</div>
<script src="__PUBLIC__/jquery_upload/js/jquery-1.8.3.min.js"></script>
<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->
<script src="__PUBLIC__/jquery_upload/js/vendor/jquery.ui.widget.js"></script>
<!-- The Load Image plugin is included for the preview images and image resizing functionality -->
<script src="__PUBLIC__/jquery_upload/js/load-image.all.min.js"></script>
<!-- The Canvas to Blob plugin is included for image resizing functionality -->
<script src="__PUBLIC__/jquery_upload/js/canvas-to-blob.min.js"></script>
<!-- Bootstrap JS is not required, but included for the responsive demo navigation -->
<script src="__PUBLIC__/jquery_upload/js/bootstrap.min.js"></script>
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="__PUBLIC__/jquery_upload/js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="__PUBLIC__/jquery_upload/js/jquery.fileupload.js"></script>
<!-- The File Upload processing plugin -->
<script src="__PUBLIC__/jquery_upload/js/jquery.fileupload-process.js"></script>
<!-- The File Upload image preview & resize plugin -->
<script src="__PUBLIC__/jquery_upload/js/jquery.fileupload-image.js"></script>
<!-- The File Upload audio preview plugin -->
<script src="__PUBLIC__/jquery_upload/js/jquery.fileupload-audio.js"></script>
<!-- The File Upload video preview plugin -->
<script src="__PUBLIC__/jquery_upload/js/jquery.fileupload-video.js"></script>
<!-- The File Upload validation plugin -->
<script src="__PUBLIC__/jquery_upload/js/jquery.fileupload-validate.js"></script>
<script>
/*jslint unparam: true, regexp: true */
/*global window, $ */
$(function () {
    'use strict';
    // Change this to the location of your server-side upload handler:
//  var url = window.location.hostname === 'blueimp.github.io' ?
//              '//jquery-file-upload.appspot.com/' : 'server/php/',
    var url="{:U('AppGroup/upload_post')}",          
        uploadButton = $('<button/>')
            .addClass('btn btn-primary')
            .prop('disabled', true)
            .text('Processing...')
            .on('click', function () {
                var $this = $(this),
                    data = $this.data();
                $this
                    .off('click')
                    .text('中断')
                    .on('click', function () {
                        $this.remove();
                        data.abort();
                    });
                data.submit().always(function () {
                    $this.remove();
                });
            });
    $('#fileupload').fileupload({
        url: url,
        dataType: 'json',
        autoUpload: false,
        acceptFileTypes: /(\.|\/)(mp3)$/i,
        maxFileSize: 1000000*100, // 100MB
        // Enable image resizing, except for Android and Opera,
        // which actually support image resizing, but fail to
        // send Blob objects via XHR requests:
        disableImageResize: /Android(?!.*Chrome)|Opera/
            .test(window.navigator.userAgent),
        previewMaxWidth: 100,
        previewMaxHeight: 100,
        previewCrop: true
    }).on('fileuploadadd', function (e, data) {
        data.context = $('<div/>').appendTo('#files');
        $.each(data.files, function (index, file) {
            var node = $('<p/>')
                    .append($('<span/>').text(file.name));
            if (!index) {
                node
                    .append('<br>')
                    .append(uploadButton.clone(true).data(data));
            }
            node.appendTo(data.context);
             var _input="<input type='hidden' name='name[]' value='"+file.name+ "'/>"
             $("#myform1").append(_input);
        });
    }).on('fileuploadprocessalways', function (e, data) {
        var index = data.index,
            file = data.files[index],
            node = $(data.context.children()[index]);
        if (file.preview) {
            node
                .prepend('<br>')
                .prepend(file.preview);
        }
        if (file.error) {
            node
                .append('<br>')
                .append($('<span class="text-danger"/>').text(file.error));
        }
        if (index + 1 === data.files.length) {
            data.context.find('button')
                .text('上传')
                .prop('disabled', !!data.files.error);
        }
    }).on('fileuploadprogressall', function (e, data) {
        var progress = parseInt(data.loaded / data.total * 100, 10);
        $('#progress .progress-bar').css(
            'width',
            progress + '%'
        );
    }).on('fileuploaddone', function (e, data) {
        $.each(data.result.files, function (index, file) {
            if (file.url) {
                var link = $('<a>')
                    .attr('target', '_blank')
                    .prop('href', file.url);
                $(data.context.children()[index])
                    .wrap(link);
          var _input="<input type='hidden' name='video[]' value='"+file.url+ "'/>"
          $("#myform1").append(_input);
            } else if (file.error) {
                var error = $('<span class="text-danger"/>').text(file.error);
                $(data.context.children()[index])
                    .append('<br>')
                    .append(error);
            }
        });
    }).on('fileuploadfail', function (e, data) {
        $.each(data.files, function (index, file) {
            var error = $('<span class="text-danger"/>').text('文件上传失败.');
            $(data.context.children()[index])
                .append('<br>')
                .append(error);
        });
    }).prop('disabled', !$.support.fileInput)
        .parent().addClass($.support.fileInput ? undefined : 'disabled');
});
</script>
</body> 
</html>
